package vip.meeet.algorithm.str;


public class Num557 {

    public static void main(String[] args) {

        String a = "Let's take LeetCode contest";
        System.out.println(reverseWords(a));
    }

    public static String reverseWords(String s) {
        String[] parts = s.substring(1,s.length()-1).split(" ");
        StringBuffer sb = new StringBuffer();
        for(String part : parts){
            sb.append(reverse(part)).append(" ");
        }
        return sb.toString().trim();
    }

    public static String reverse(String s){
        char[] rs = new char[s.length()];
        int len = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            rs[len++] = s.charAt(i);
        }
        return new String(rs);
    }


}
